home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / asm_msc1.arc / GETDIGIT.ASM < prev    next >
Assembly Source File  |  1988-11-20  |  7KB  |  193 lines

  1.  
  2.        page    64,132
  3.        title   GETDIGIT-gets a digit for DOS batch file processing
  4.        subttl  by Tony Alan Rhea 10/26/83
  5. ;
  6. ;
  7. comment *
  8.  
  9.        This program accepts a prompt from the command line and accepts
  10.        a one digit response to that prompt.  On exit, the DOS ERRORLEVEL
  11.        is set to the digit.  Non-numeric keys are ignored and <Ctrl><Break>
  12.        will not exit.
  13.  
  14.        This program requires DOS 2.0.
  15.  
  16.        Usage:
  17.              GETDIGIT prompt
  18.        where "prompt" is the message to displayed to the user.
  19.  
  20.        Example batch file usage:
  21.           echo off
  22.           :menu
  23.           cls
  24.           echo ---IBM PC Menu--
  25.           echo 1 - Run Wordstar
  26.           echo 2 - Run Dbase II
  27.           echo 3 - Exit to  DOS
  28.           GETDIGIT Please enter an option number:
  29.           if errorlevel 4 goto menu
  30.           if errorlevel 3 goto end
  31.           if errorlevel 2 goto dbase
  32.           if errorlevel 1 goto wordstar
  33.           :if we get here nothing matched -- try again
  34.           goto menu
  35.           :wordstar
  36.           cls
  37.           echo We would run WORDSTAR here.
  38.           pause
  39.           goto menu
  40.           :dbase
  41.           cls
  42.           echo We would run DBASE here.
  43.           pause
  44.           goto menu
  45.           :end
  46.           cls
  47.           echo on
  48.  
  49.        Copyright (C) 1983  Tony Alan Rhea
  50.        This program may be copied and distributed for personal use
  51.        but not for profit provided this notice is included.  Author makes
  52.        no warranty, expressed or implied, as to the correct nature and
  53.        operation of this software.
  54.  
  55.  
  56.        You may make and distribute as many copies of this program as you wish
  57.        for your PERSONAL use only ( NOT for business purposes, please! ).
  58.        Feel free to modify, mutilate, or adulterate this program.  If you come
  59.        up with an bug or improvement, please let me know by writing me at this
  60.        address:
  61.                Tony A. Rhea
  62.                1030 Ivy Lane
  63.                Cary, NC  27511
  64.        If you do modify it, please give me credit in the program.  This helps
  65.        to preserve my ego and increase my fame (but, unfortunately, NOT my
  66.        financial status).  Also, I would appreciate a copy of the modified
  67.        version, preferably on disk (I'll be happy to return your diskette).
  68.  
  69.        If you like this program ( or HATE it ), please let me know.  Drop me
  70.        a line at the address given above.
  71.  
  72.        This program has been submitted for publication in PC-WORLD magazine.
  73.  
  74.  
  75.          Revision history:
  76.             rev 1.0  10/26/83                         { original release }
  77.  
  78.  
  79.        *
  80.        page
  81. ;
  82. ;
  83. ; Equates
  84. ;
  85. ;
  86. zero   equ     '0'
  87. nine   equ     '9'
  88. cr     equ     0dh
  89. lf     equ     0ah
  90. dollar equ     '$'
  91. ;
  92. ;
  93. ; Program entry point
  94. ;
  95. ;
  96. cseg   segment para 'code'
  97.        assume  cs:cseg, ds:cseg, ss:nothing, es:cseg
  98.        org     100h            ;for .COM file
  99. entry  proc    near
  100.        mov     ah,30h          ;set function code -- get DOS version number
  101.        int     21h             ;and request DOS service
  102.        cmp     al,0            ;is it pre-DOS 2.0?
  103.        jne     entry10         ;if not, continue
  104.        jmp     dosexit         ;else tell user & quit
  105. ;
  106. ;
  107. ; At this point we have DOS 2.0 or better.  Get the prompt bytes from the
  108. ; command line paramter area and display them one at a time.  Skip the first
  109. ; character which should be a blank and the last character which is a <CR>.
  110. ; The number of characters on the command line is at PSP+80h and the parms
  111. ; themselves start at PSP+81h, so we copy bytes starting at PSP+82h.
  112. ;
  113. ;
  114. entry10 label  near
  115.        push    cs              ;save CS and
  116.        pop     ds              ;point DS to CS -- establish addressability
  117.        xor     cx,cx           ;clear CX
  118.        mov     si,80h          ;set up address of parm length in PSP
  119.        mov     cl,[si]         ;and get parm length into CL
  120.        cmp     cl,0            ;any prompt to display?
  121.        je      entry30         ;if not, then just go read a key
  122.        dec     cl              ;else set CX one less cause we don't want the <CR>
  123.        mov     si,82h          ;point SI to command line parm (one space skipped)
  124. entry20 label  near
  125.        mov     dl,[si]         ;get a character into DL
  126.        mov     ah,02           ;set function code -- display char in DL
  127.        int     21h             ;and request DOS service
  128.        inc     si              ;point to next character and
  129.        loop    entry20         ;loop until all characters have been displayed
  130.        page
  131. ;
  132. ;
  133. ; The prompt has been displayed.  Get the user's response.
  134. ; Clear the keyboard buffer and wait for a key without echo.
  135. ; Keep monitoring the keyboard until we get a numeric entry.
  136. ; This input function DOES NOT check for control break!
  137. ; The cursor is at the end of the prompt.
  138. ;
  139. ;
  140. entry30 label  near
  141.        mov     ax,0c07h        ;set function code = read key clearing buffer
  142.        int     21h             ;and request DOS service
  143.        cmp     al,0            ;is it an extended code?
  144.        jne     entry40         ;if not, skip over read of second char
  145.        mov     ah,07           ;else set function code = read key from buffer
  146.        int     21h             ;and request DOS to get it -- we throw it away
  147.        jmp     entry30         ;and try again since we want a non-extended key
  148. entry40 label  near
  149.        cmp     al,zero         ;is the character < zero?
  150.        jb      entry30         ;if so, then read another key
  151.        cmp     al,nine         ;is the character > nine?
  152.        ja      entry30         ;if so, then read another key
  153. ;
  154. ;
  155. ; If we get here we have read a valid key into AL.  Display the character
  156. ; and set the DOS errorlevel to that digit.
  157. ;
  158. ;
  159.        push    ax              ;save the character a moment
  160.        mov     dl,al           ;move the character into DL
  161.        mov     ah,2            ;set function code -- display character in DL
  162.        int     21h             ;and request DOS service
  163.        pop     ax              ;restore saved character into AX
  164.        sub     al,zero         ;convert '0' to 0, '1' to 1, etc...
  165.        mov     ah,4ch          ;set DOS function code -- terminate with errorlevel
  166.        int     21h             ;and request DOS service (requested errorlevel returned)
  167.        page
  168. ;
  169. ;
  170. ; If we get here we don't have DOS 2.0.  Tell user about it and terminate via
  171. ; function 0 (which works for all DOS versions).
  172. ;
  173. ;
  174. dosexit label near
  175.        lea     dx,errmsg1      ;point DX to DOS error msg
  176.        mov     ah,9            ;set function code -- print string
  177.        int     21h             ;and request DOS service
  178.        xor     ax,ax           ;set function code to zero -- program terminate
  179.        int     21h             ;and request DOS service (no errorlevel returned)
  180. entry  endp
  181.        page
  182. ;
  183. ;
  184. ; Messages
  185. ;
  186. ;
  187. errmsg1 db     'GETDIGIT requires DOS 2.0 or greater.', cr, lf, dollar
  188. copyright db   'GETDIGIT -- Copyright (C) 1983 Tony Alan Rhea'
  189. ;
  190. ;
  191. cseg   ends
  192.        end     entry
  193.